package com.haier.cre.commonframe.base;

import android.os.Handler;
import android.os.Looper;
import android.support.multidex.MultiDexApplication;

import com.blankj.utilcode.util.Utils;
import com.facebook.stetho.Stetho;

/**
 * 项目名：CommonLibrary
 * 包 名：com.haier.cre.commonframe.base
 * 创建人：18002063
 * 日 期：2018/10/15
 * 简 述：程序入口
 */
public class LibApplication extends MultiDexApplication {
    /**
     * 获取到主线程的上下文
     */
    public static LibApplication mContext = null;
    /**
     * 获取到主线程的handler
     */
    private static Handler mMainThreadHandler = null;
    /**
     * 获取到主线程的looper
     */
    private static Looper mMainThreadLooper = null;
    /**
     * 获取到主线程
     */
    private static Thread mMainThead = null;
    /**
     * 获取到主线程的id
     */
    private static int mMainTheadId;


    @Override
    public void onCreate() {
        super.onCreate();
        init();
    }

    /**
     * Application的初始化全部放在这里
     */
    private void init() {
        this.mContext = this;
        this.mMainThreadHandler = new Handler();
        this.mMainThreadLooper = getMainLooper();
        this.mMainThead = Thread.currentThread();
        this.mMainTheadId = android.os.Process.myTid();

        //工具类初始化
        Utils.init(mContext);

        //Stetho调试工具初始化
        Stetho.initializeWithDefaults(this);
    }

    /**
     * 获取主线程的 上下文
     *
     * @return
     */
    public static LibApplication getApplication() {
        return mContext;
    }

    /**
     * 获取主线程的Handler
     *
     * @return
     */
    public static Handler getMainThreadHandler() {
        return mMainThreadHandler;
    }

    /**
     * 获取主线程的Looper
     *
     * @return
     */
    public static Looper getMainThreadLooper() {
        return mMainThreadLooper;
    }

    /**
     * 获取主线程
     *
     * @return
     */
    public static Thread getMainThread() {
        return mMainThead;
    }

    /**
     * 获取主线程ID
     *
     * @return
     */
    public static int getMainThreadId() {
        return mMainTheadId;
    }
}
